package com.vader.springcloud.controller;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.vader.springcloud.service.PaymentHystrixService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author kaivader
 */
@RestController
@RequestMapping("/hystrix")
@DefaultProperties(defaultFallback = "globalFallback")
public class HystrixFeignController {
    @Resource
    private PaymentHystrixService hystrixService;

    @GetMapping("/ok/{id}")
    public String ok(@PathVariable Integer id) {
        return hystrixService.ok(id);
    }

    @GetMapping("/timeout/{id}")
//    @HystrixCommand(fallbackMethod = "timeoutFallback", commandProperties = {
//            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "1500")
//    })
    @HystrixCommand
    public String timeout(@PathVariable Integer id) {
        return hystrixService.timeOut(id);
    }

    public String globalFallback() {
        return "消费端系统繁忙，请稍后再试。";
    }


}
